//
//  ClockViewController.m
//  MooreDoll
//
//  Created by Orange on 2014/12/25.
//  Copyright (c) 2014年 Tank. All rights reserved.
//


#import "RecorderViewController.h"
#import "SongListViewController.h"
#import "ClockView.h"
#import "ClockViewController.h"
#import "UserDefaults.h"
#import "ConfigOfKey.h"
@interface ClockViewController ()<ClockViewDelegate,SongListViewControllerDelegate,RecorderViewControllerDelegate>
@property (weak, nonatomic) IBOutlet UISwitch *clockSwitch;

@end

@implementation ClockViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [_clockSwitch setOn: [[UserDefaults get: kUserDefaultsClockSwitch] boolValue]];
    [(ClockView *)self.view clockStateOn: _clockSwitch.on];
    
    NSArray  *array  = [UserDefaults get: kUserDefaultsClockSeleteDay];
    NSString *yymmdd = [UserDefaults get: kUserDefaultsClockYYMMDD];
    NSString *times  = [UserDefaults get: kUserDefaultsClockTime];
    
    [(ClockView *) self.view clockSelectedWeek: array atYYMMDD: yymmdd atTime: times];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)clockSwitchPress: (UISwitch *)sender {
    [UserDefaults set: [NSNumber numberWithBool: sender.on ] withKey: kUserDefaultsClockSwitch ];
    [(ClockView *)self.view clockStateOn: sender.on];
}
#pragma mark - ClockViewDelegate
- (void) clockViewChangeMusic {
}
- (void) clockViewStopAction  {
}
- (void) clockViewSavePress:(NSMutableArray *)array atYYMMDD:(NSString *)yymmdd atTime:(NSString *)times {
    
    [UserDefaults set: array  withKey: kUserDefaultsClockSeleteDay];
    [UserDefaults set: yymmdd withKey: kUserDefaultsClockYYMMDD];
    [UserDefaults set: times  withKey: kUserDefaultsClockTime];
    [self.navigationController popViewControllerAnimated: YES];
}
- (void) clockViewClearPress  {
    [self.navigationController popViewControllerAnimated: YES];
}
- (void) clockViewSystemMusicSelect {

}
- (void) clockViewLocalMusicSelect {
    SongListViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:@"SongListViewController"];
    [svc setDelegate: self];
    [self.navigationController pushViewController: svc animated: YES];
}
- (void)clockViewRecoderForMe {
    RecorderViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:@"RecorderViewController"];
    [svc setDelegate: self];
    [self.navigationController pushViewController: svc animated: YES];
}
#pragma mark - SongListViewControllerDelegate
-(void)sendAudioToXMPPWithDataPath:(NSString *)mp3Path andFileName:(NSString *)fileName andPathInApp:(NSString *)pathInApp {
    [UserDefaults set: mp3Path withKey: kUserDefaultsClockMusic];
}
#pragma mark - RecorderViewControllerDelegate
- (void)recorderViewControllerFilePath:(NSString *)path {
    [UserDefaults set: path withKey: kUserDefaultsClockMusic];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
